import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:mtf/R.dart';
import 'package:mtf/app/modules/recharge_module/recharge_controller.dart';
import 'package:mtf/app/theme/app_colors.dart';
import 'package:mtf/app/widget/AppBarLeftTitle.dart';
import 'package:mtf/app/widget/SettingBar.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class rechargePage extends GetView<rechargeController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarLeftTitle(
        title: "充值",
      ),
      body: ListView.builder(
        itemBuilder: (context, index) {
          if (index == 0) {
            return Container(
              margin: EdgeInsets.all(10),
              padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(10)),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    "充值金额",
                    style: TextStyle(color: c_333333, fontSize: 15),
                  ),
                  TextField(
                    keyboardType: TextInputType.numberWithOptions(
                        decimal: true),
                    inputFormatters: [
                      FilteringTextInputFormatter.allow(RegExp("[0-9.]"))
                    ],
                    onChanged: (value) {
                      if (value.contains(".")) {
                        var vv = value.split('.');
                        if (vv.length > 2) {
                          controller.valueController.text = '${vv[0]}.${vv[1]}';
                        }
                        controller.valueController.selection =
                            TextSelection.fromPosition(TextPosition(
                                offset: controller.valueController.text
                                    .length));
                      }
                    },
                    decoration: InputDecoration(
                      contentPadding: const EdgeInsets.fromLTRB(0, 15, 20, 14),
                      hintText: "请输入买入金额",
                      hintStyle: TextStyle(fontSize: 18, color: c_bbbbbb),
                      suffixIcon: Padding(
                        padding: const EdgeInsets.all(15.0),
                        child: Text(
                          "USD",
                          style: TextStyle(
                              fontSize: 24,
                              fontWeight: FontWeight.bold,
                              color: c_333333),
                        ),
                      ),
                      border: InputBorder.none,
                    ),
                    style: TextStyle(color: c_333333, fontSize: 18),
                    controller: controller.valueController,
                  ),
                  Divider(
                    height: 1,
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  Row(
                    children: [
                      Obx(() {
                        return Text("预计需要支付人民币:￥${controller.preAccount.value}",
                            style: TextStyle(color: c_999999, fontSize: 12));
                      }),
                      // Text(
                      //   "0 USD",
                      //   style: TextStyle(color: c_f12f38, fontSize: 12),
                      // ),
                    ],
                  )
                ],
              ),
            );
          } else if (index == 1) {
            return Container(
              margin: EdgeInsets.all(10),
              padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(10)),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start, children: [
                Text(
                  "支付方式", style: TextStyle(color: c_333333, fontSize: 14),),
                Obx(() {
                  return SettingBar(
                    paddingHorizontal: 0,
                    paddingVertical: 5,
                    leftIcon: SvgPicture.asset(R.assetsImgIcSvgPay),
                    leftText: "线下支付",
                    leftIconSpace: 10,
                    rightIcon: Checkbox(
                        value: controller.CheckObs,
                        shape: CircleBorder(),
                        checkColor: Colors.white,
                        activeColor: Colors.red,
                        onChanged: (value) {
                          controller.CheckObs = !controller.CheckObs;
                        }),);
                })
              ],),
            );
          } else {
            return Container(
              margin: const EdgeInsets.only(top: 30, left: 10, right: 10),
              width: double.maxFinite,
              height: 48,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(24),
                color: c_f12f38,
              ),
              child: TextButton(
                  child: Text("提交",
                      style: TextStyle(
                          color: Colors.white,
                          fontSize: 16,
                          fontWeight: FontWeight.bold)),
                  onPressed: () {
                    controller.clickRecharge();
                  }),
            );
          }
        },
        itemCount: 3,
        shrinkWrap: true,
      ),
    );
  }
}
